package com.ice.delay.task.controller;

import com.ice.delay.task.service.DelayTaskUserService;
import com.ice.delay.task.vo.req.UserCreateVoReq;
import com.ice.delay.task.vo.req.UserDeleteVoReq;
import com.ice.delay.task.vo.req.UserVoReq;
import com.ice.delay.task.vo.res.UserVoRes;
import com.ice.framework.common.annotation.AutoResult;
import com.ice.framework.common.base.RPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author wangwei
 * @Date 2023/5/12 14:23
 */
@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private DelayTaskUserService delayTaskUserService;

    @AutoResult
    @ResponseBody
    @PostMapping("/page")
    public RPage<UserVoRes> page(@RequestBody RPage<UserVoReq> page) {
        return delayTaskUserService.pageUser(page);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("/create")
    public void create(@RequestBody @Valid UserCreateVoReq userCreateVoReq) {
        delayTaskUserService.createUser(userCreateVoReq);
    }

    @AutoResult
    @ResponseBody
    @PostMapping("/delete")
    public void delete(@RequestBody @Valid UserDeleteVoReq userDeleteVoReq) {
        delayTaskUserService.deleteUser(userDeleteVoReq);
    }


    @RequestMapping("/index")
    public String index() {
        return "/admin/user";
    }
}
